/* Copyright (c) 2009, Real-Time Innovations, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * - Redistributions of source code must retain the above copyright notice,
 *   this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 * - Neither the name of Real-Time Innovations, Inc. nor the names of its
 *   contributors may be used to endorse or promote products derived from
 *   this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

package org.omg.dds.infrastructure;

import org.omg.dds.spi.ServiceImpl;
import org.omg.dds.util.ValueType;


/**
 * DDS/Duration.java .
 * Generated by the IDL-to-Java compiler (portable), version "3.2"
 * from dds_rtf2_dcps.idl
 * Wednesday, September 16, 2009 9:06:02 AM CDT
 */
public abstract class Duration implements ValueType<Duration> {
    // -----------------------------------------------------------------------
    // Constants
    // -----------------------------------------------------------------------

    private static final long serialVersionUID = -2332895302431993362L;

    public static final int INFINITE_SEC = Integer.MAX_VALUE;
    public static final int INFINITE_NSEC = Integer.MAX_VALUE;

    public static final int ZERO_SEC = 0;
    public static final int ZERO_NSEC = 0;



    // -----------------------------------------------------------------------
    // Object Lifecycle
    // -----------------------------------------------------------------------

    /**
     * Create a Duration of zero length.
     */
    public static Duration create() {
        Duration duration =
            ServiceImpl.getInstance().getSimpleDataFactory().createDuration();
        assert duration != null;
        return duration;
    }
    
    
    public static Duration create(int sec, int nanosec) {
        Duration duration =
            ServiceImpl.getInstance().getSimpleDataFactory().createDuration(
                    sec, nanosec);
        assert duration != null;
        return duration;
    }
    
    
    public static Duration create(Duration src) {
        Duration duration =
            ServiceImpl.getInstance().getSimpleDataFactory().createDuration(
                    src);
        assert duration != null;
        return duration;
    }
    
    
    protected Duration() {
        // empty
    }


    @Override
    public abstract Duration clone();



    // -----------------------------------------------------------------------
    // Methods
    // -----------------------------------------------------------------------

    // --- Data access: ------------------------------------------------------

    /**
     * @param sec the sec to set
     */
    public abstract void setSec(int sec);

    /**
     * @return the sec
     */
    public abstract int getSec();

    /**
     * @param nanosec the nanosec to set
     */
    public abstract void setNanosec(int nanosec);

    /**
     * @return the nanosec
     */
    public abstract int getNanosec();


    // --- Manipulation: -----------------------------------------------------

    public abstract void add(Duration duration);

    public abstract void addSec(int sec);

    public abstract void addNanosec(int nanosec);

    public abstract void addMillis(long millis);


    // --- Conversion: -------------------------------------------------------

    /**
     * Round or truncate this Duration to a whole number of milliseconds.
     */
    public abstract long toMillis();

    public abstract long toNanosec();

    public abstract void fromMillis(long millis);

    public abstract void fromNanosec(long nanosec);

}
